<template>
<el-dialog   :visible.sync="visible" :title="title"  width="70%"  :before-close="handleClose" >



      <el-table v-loading="loading" :data="sendorderList" @selection-change="handleSelectionChange">
        <el-table-column label="单位名称" align="center" prop="zyxDevice.unitname" />
        <el-table-column label="科室/部门 " align="center" prop="useoffice" :formatter="useofficeFormat"/>
        <el-table-column label="设备类别 " align="center" prop="devicetype" />
        <el-table-column label="设备型号" align="center" prop="zyxDevice.devicemodel" />
        <el-table-column label="派工类别 " align="center" prop="sendtype" :formatter="sendtypeFormat" />
        <el-table-column label="服务状态" align="center" prop="servicestatus" :formatter="servicestatusFormat" />
        <el-table-column label="派工时间" align="center" prop="senddate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.senddate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="进行时间" align="center" prop="processdate" />
        <el-table-column label="责任人 " align="center" prop="membername" />
        <el-table-column label="备注信息" align="center" prop="remark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
            v-if="scope.row.servicestatus==='4'"
              size="mini"
              type="text"
              icon="el-icon-info"
              @click="handlePrint(scope.row)"
              v-hasPermi="['zyx:record:edit']"
            >查看</el-button>

          </template>
        </el-table-column>
      </el-table>
      <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
          <repair-print ref="repairPrint" ></repair-print>
          <takecare-print  ref="takecarePrint"   ></takecare-print>
          <check-print ref="checkPrint" ></check-print>
          <operate-print ref="operatePrint"  ></operate-print>
          <cost-print  ref="costPrint" ></cost-print>
     </el-dialog>


</template>
<script>
import { listAllSendorder} from "@/api/zyx/sendorder";
import { listMyDept,  } from "@/api/system/dept";

import repairPrint from"../sendorder/repairPrint.vue"
import takecarePrint from "../sendorder/takecarePrint.vue"
  import checkPrint from "../sendorder/checkPrint.vue"
  import operatePrint from "../sendorder/operatePrint.vue"
  import costPrint from "../sendorder/costPrint.vue"
export default {
  components: {
    repairPrint,
    takecarePrint,
    checkPrint,
    operatePrint,
    costPrint,
  },
  data() {
    return {
      visible: false,
      title:'提示',
      // 显示搜索条件
      showSearch: true,
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 派工表格数据
      sendorderList: [],
      // 派工类别 字典
      sendtypeOptions: [],
      // 服务状态字典
      servicestatusOptions: [],
      devicetypeOptions:[],
      useofficeOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 30,
        devicemodel:null,
        departid: null,
        useoffice:null,
        deviceid: null,
        sendtype: null,
        servicestatus: null,
        processdate: null,
        memberid: null,
        overdate: null,
        membername:null,
      },

    }
  },
  created() {
    this.getDicts("zyx_sendtype").then(response => {
      this.sendtypeOptions = response.data;
    });
    this.getDicts("zyx_servicestatus").then(response => {
      this.servicestatusOptions = response.data;
    });
    this.getDicts("zyx_devicetype").then(response => {
         this.devicetypeOptions = response.data;
       });
     listMyDept({deptType:'2'}).then(response => {
       // console.log(response)
       this.useofficeOptions = response.data;
     });
  },
  methods: {
    handlePrint(row){
      // console.log(row);
      if(row.sendtype==='1'){
        this.$refs.repairPrint.zyxSendorder=row
        this.$refs.repairPrint.zyxDevice=row.zyxDevice
        this.$refs.repairPrint.getbill(row.id);
        this.$refs.repairPrint.getname();
        this.$refs.repairPrint.visible = true;
      }else if(row.sendtype==='2'){//保养
        this.$refs.takecarePrint.zyxSendorder=row
        this.$refs.takecarePrint.zyxDevice=row.zyxDevice

        this.$refs.takecarePrint.getbill(row.id);
        this.$refs.takecarePrint.getname();
        this.$refs.takecarePrint.visible = true;
      }else if(row.sendtype==='3'){//检定

        this.$refs.checkPrint.zyxSendorder=row
        this.$refs.checkPrint.zyxDevice=row.zyxDevice

        this.$refs.checkPrint.getbill(row.id);
        this.$refs.checkPrint.getname();
        this.$refs.checkPrint.visible = true;
      }else if(row.sendtype==='4'){//运营相关

      this.$refs.operatePrint.zyxSendorder=row
      this.$refs.operatePrint.zyxDevice=row.zyxDevice
      this.$refs.operatePrint.getbill(row.id);
      this.$refs.operatePrint.getname();
      this.$refs.operatePrint.visible = true;

      }

    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        departid: null,
        deviceid: null,
        sendtype: null,
        devicestatus: null,
        servicestatus: null,
        senddate: null,
        processdate: null,
        memberid: null,
        overdate: null,
        useoffice:null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
   /** 查询派工列表 */
      getList() {
        this.loading = true;
        // console.log(this.queryParams)
        listAllSendorder(this.queryParams).then(response => {
          this.sendorderList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 派工类别 字典翻译
      sendtypeFormat(row, column) {
        return this.selectDictLabel(this.sendtypeOptions, row.sendtype);
      },
      // 服务状态字典翻译
      servicestatusFormat(row, column) {
        return this.selectDictLabel(this.servicestatusOptions, row.servicestatus);
      },
      // 设备类别字典字典翻译
      devicetypeFormat(row, column) {
        return this.selectDictLabel(this.devicetypeOptions, row.devicetype);
      },
      // 使用科室字典字典翻译
      useofficeFormat(row, column) {
        // console.log(this.selectDeptLabel(this.useofficeOptions, row.useoffice))
        return this.selectDeptLabel(this.useofficeOptions, row.useoffice);
      },

  }
}
</script>

<style lang="scss" scoped>

</style>
